package com.zlx.rulemk.marketing.dao;

import com.zlx.rulemk.marketing.beans.EventBean;
import com.zlx.rulemk.marketing.beans.EventCondition;
import com.zlx.rulemk.marketing.beans.PropertiesBean;
import com.zlx.rulemk.marketing.utils.EventUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhanglingxing
 * @CreateTime: 2022-07-06
 * @Description: 判断触发规则是否匹配
 * @Version: 1.0
 */
public class TriggerQuerier {

    /**
     * 比较日志数据和规则条件是否匹配
     * @param bean
     * @param eventCondition
     * @return
     */
    public boolean triggerEventMatchCondition(EventBean bean, EventCondition eventCondition) {

        if(bean != null && StringUtils.isNotBlank(bean.getEventId())){ //增强代码的健壮性
            if (bean.getEventId().equals(eventCondition.getEventId())) {

                List<PropertiesBean> eventProps = eventCondition.getEventProps();
                /**
                 * 判断 规则中的属性是否等于触发事件
                 */
                return EventUtil.ComparProperties(bean,eventProps);
            }
        }
        return false;
    }

}
